<template>
  <van-address-edit 
  :area-list="areaList"
  show-set-default
  :address-info ="address"
  :area-columns-placeholder="['请选择', '请选择', '请选择']"
  @save="onSave"
  />
</template>
<script setup>
//引入地区数据
import { areaList } from '@vant/area-data'
const { proxy } = getCurrentInstance()

let address = ref({})
const business = proxy.$business.value

onBeforeMount(() => address.value = {
        name: business.nickname,
        tel: business.mobile,
        areaCode: business.district || business.city || business.province,
    })


const onSave =async (values)=>{

    //组装数据
    var params = {
        busid:business.id,
        consignee:values.name,
        address:values.addressDetail,
        mobile:values.tel,
        status:values.isDefault ? "1" : "0",
        code:values.areaCode
    }

    //发送请求
    var res = await proxy.$POST({
        url:'address/add',
        params
    })

    if(res.code == 0){
        proxy.$fail(res.msg)
        return
    }
    proxy.$success({
        message:res.msg,
        duration:1000,
        onClose:()=>{
            proxy.$router.go(-1)
            return
        }
    })

    console.log(values)
    console.log(params)
}
</script>